package com.example.xungeng2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xungeng2.pojo.SendInfo;
import com.example.xungeng2.pojo.Worker;
import com.example.xungeng2.pojo.Xglx;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface WorkerMapper extends BaseMapper<Worker> {
    @Select("select * from send_info where user_id=#{userId}")
    List<SendInfo> selectInfo(Integer userId);

    @Select("select id from user_clock where user_id=#{userId} and time=#{time}")
    Integer findUserClock(Integer userId, String time);

    @Select("select time from user_clock where user_id=#{userId}")
    List<String> findHistoryUserClock(Integer userId);

    @Insert("insert into user_clock (user_id,time) values(#{userId},#{time})")
    void userClock(Integer userId, String time);

    @Insert("insert into userkq (userId,name,dkTime,detailTime) values(#{userId},#{realName},#{time},#{detailTime})")
    void addUserKQTJ(Integer userId, String realName, String time, String detailTime);

    @Select("select id from xglx where sign=0 and user_id=#{userId}")
    Integer selectXGLXId(Integer userId);

    @Select("select id from xglx where sign=0 and user_id=#{userId}")
    void insertXGLXOverTime(String overTime, Integer id);


    @Select("select start_time from xglx where sign=0 and user_id=#{userId}")
    String selectStartTime(Integer userId);

    @Update("update xglx set sign=1 where user_id=#{userId}")
    void updateXGLXSign(Integer userId);

    @Select("select not_num from worker work_id=#{userId}")
    int selectRWLCNumById(Integer userId);

    @Select("select id from userkq where user_id=#{userId} and dk_time=#{dkTime}")
    Integer selectUserToday(Integer userId, String format);

    @Update("update userkq set lcnum=#{num} where user_id=#{userId}")
    void updateUserKQTJ(Integer userId, int num);

    @Insert("insert into xglx (user_id,start_time,sign) values(#{userId},#{startTime},0)")
    void insertXGLX(Integer userId, String startTime);

    @Select("select * from xglx where user_id=#{userId}")
    List<Xglx> selectXGHistory(Integer userId);

    @Insert("insert into workers (user_id,task_num,not_num) values(#{userId},0,0)")
    void createUserTask(int userId);

    @Update("update workers set task_num=task_num+1,not_num=not_num+1 where user_id=#{userId}")
    void updateUserTaskNum(int userId);
}
